package org.uniview.common.util;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeHelper {

	public static String date2String(long dateCount) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date currentTime_1 = new Date(dateCount);
		if (currentTime_1 == null)
			return "";
		String dateString = formatter.format(currentTime_1);
		return dateString;

	}

	public static String date2String(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date currentTime_1 = date;
		if (currentTime_1 == null)
			return "";
		String dateString = formatter.format(currentTime_1);
		return dateString;

	}

	public static long string2Date(String dateString) {
		// Parse the previous string back into a Date.
		if (dateString == null)
			return 0;
		//if (SchUtil.DEBUG) System.out.println("not null");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		ParsePosition pos = new ParsePosition(0);
		Date currentTime_2 = formatter.parse(dateString.trim(), pos);
		if (currentTime_2 == null)
			return 0;
		//if (SchUtil.DEBUG) System.out.println("parse not null");
		return currentTime_2.getTime();
	}

	public static Date string2DateTime(String dateString) {
		// Parse the previous string back into a Date.
		if (dateString == null)
			return null;
		//if (SchUtil.DEBUG) System.out.println("not null");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		ParsePosition pos = new ParsePosition(0);
		Date currentTime_2 = formatter.parse(dateString.trim(), pos);
		//if (SchUtil.DEBUG) System.out.println("parse not null");
		return currentTime_2;
	}
}
